package com.caocao.exception;

import com.caocao.domain.RequestResult;
import com.caocao.utils.RequestResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 描述:捕获系统中的异常信息
 *
 * @Author:操文健
 * @Create Time:2017-09-10 6:04
 */
@ControllerAdvice
public class HandException {

    private static final Logger logger = LoggerFactory.getLogger(HandException.class);

    @ExceptionHandler(value = Exception.class)  // 捕获何种类型的异常信息
    @ResponseBody // 需要返回界面的数据信息使用的注解
    public RequestResult handle(Exception e) {
        logger.error("捕获异常信息:", e);
        return RequestResultUtil.error(e.getMessage());
    }

}
